package main

import (
	"encoding/json"
	"fmt"
)

type Person struct {
	Name string
	Age  int
}

func updateAge(p *Person) {
	p.Age = 20
}

type Address struct {
	City  string
	Email string
}

type Employee struct {
	Msg  Person
	Addr Address
}

type Animal struct {
	Name string
}

type Dog struct {
	Animal //匿名嵌入 类似于 "继承"
	Skin   string
}

type User struct {
	Id    int    `json:id`
	Name  string `json:name`
	Email string `json:email`
}

func main() {

	alen := &Person{Name: "Alen", Age: 18}
	fmt.Println("name is ", alen.Name)
	fmt.Println("age is ", alen.Age)

	e := Employee{
		Msg: Person{
			Name: "Tom",
			Age:  20,
		},
		Addr: Address{
			City:  "ShangHai",
			Email: "xxx@xxx.com",
		},
	}
	fmt.Println("e city is ", e.Addr.City)

	d := Dog{Animal: Animal{Name: "HotDog"}, Skin: "Golden"}
	fmt.Println(d)

	data := `{"id":12.9, "name":"Nexora","email":"1816sd564xcv1@163.com"}`
	var u User
	json.Unmarshal([]byte(data), &u)
	fmt.Println(u.Id)
	fmt.Println(u.Name)
	fmt.Println(u.Email)
}
